package com.ruoyi.lm.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.EmptyUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lm.domain.LmSerinfocase;
import com.ruoyi.lm.service.ILmSerinfocaseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务案例Controller
 * 
 * @author ruoyi
 * @date 2020-09-02
 */
@Controller
@RequestMapping("/phone/lm/serinfocase")
public class LmSerinfocaseControllerPhone extends BaseController
{

    @Autowired
    private ILmSerinfocaseService lmSerinfocaseService;

    /**
     * 查询服务案例列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestBody LmSerinfocase lmSerinfocase)
    {
        List<LmSerinfocase> list = lmSerinfocaseService.selectLmSerinfocaseList(lmSerinfocase);
        for(int i=0;i<list.size();i++){
           LmSerinfocase temp = list.get(i);
           if(EmptyUtils.isNotEmpty(temp.getCaseImages())){
               String[] arr = temp.getCaseImages().split(",");
               temp.setArrImages(arr);
           }
        }
        return getDataTable(list);
    }

    /**
     * 新增保存服务案例
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody LmSerinfocase lmSerinfocase)
    {
        //获取图片
        String[] images = lmSerinfocase.getCaseImages().split(",");
        lmSerinfocase.setCasePic(images[0]);
        return toAjax(lmSerinfocaseService.insertLmSerinfocase(lmSerinfocase));
    }

    /**
     * 修改保存服务案例
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody LmSerinfocase lmSerinfocase)
    {

        return toAjax(lmSerinfocaseService.updateLmSerinfocase(lmSerinfocase));
    }

    /**
     * 删除服务案例
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lmSerinfocaseService.deleteLmSerinfocaseByIds(ids));
    }
}
